package com.lancoo.answer.util.paperUtils.fragmentUtils.child;

import android.text.TextUtils;

import androidx.fragment.app.Fragment;

import com.lancoo.answer.model.ConstantBean;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.Ques;
import com.lancoo.answer.ui.child.lookReview.ChildClozeLookReviewFragment;
import com.lancoo.answer.ui.child.lookReview.ChildWordListenWriteLookReviewFragment;
import com.lancoo.answer.ui.child.original.ChildFillOriginalFragment;
import com.lancoo.answer.ui.child.original.ChildMatchOriginalFragment;
import com.lancoo.answer.ui.child.original.ChildReadMatchOriginalFragment;
import com.lancoo.answer.ui.child.original.ChildSelectOriginalFragment;
import com.lancoo.answer.ui.child.original.CompositionOriginalFragment;
import com.lancoo.answer.ui.child.original.PassageDictationOriginalFragment;
import com.lancoo.answer.ui.ques.WaitToDockFragment;
import com.lancoo.answer.view.fragment.listenmatch.ListenMatchAnswerFragment;
import com.lancoo.answer.view.fragment.listenmatch.ListenParagraphAnalysisFragment;
import com.lancoo.answer.view.fragment.manual.ManualAnswerLookingFragment;
import com.lancoo.answer.view.fragment.option.MultiChildFragment;
import com.lancoo.answer.view.fragment.paragraphSort.ParagraphSortingChildLookingFragment;
import com.lancoo.answer.view.fragment.webquesBody.WebQuesBodyOriginalLookingFragment;

/**
 * Created by pengmi on 2022/2/20 11:49
 * Description:小题查看评阅状态fragment加载
 */
public class ChildOriginalFragmentUtils {

    public static Fragment loadChildOriginalFragment(Ques ques,
                                                     int typeIndex,
                                                     int quesIndex,
                                                     int childIndex,
                                                     int defaultLoadIndex,int defaultLoadChildexIndex,int defaultLoadItemIndex) {
        String genreID = ques.getGenreID();
        String typeNo = ques.getTypeNo();
        Child child = ques.getChildList().get(childIndex);
        int childAnswerType = child.getChildAnswerType();
        switch (genreID) {
            case "38"://句子英译中
            case "25"://英译中
            case "40"://句子中译英
            case "26"://中译英
                return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "43"://段落匹配
                return ChildMatchOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex, defaultLoadIndex);
            case "42"://阅读匹配
                return ChildReadMatchOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "20"://选词填空
                int childSize = ques.getChildList().size();
                int itemSize = ques.getChildList().get(0).getItemList().size();
                if (childSize > itemSize) {//句子场景
                    return ChildFillOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                } else {//短文场景
//                    return WebQuesBodyLookingFragment.Companion.loadFragment(typeIndex, quesIndex, 0, defaultLoadIndex);
                    return WebQuesBodyOriginalLookingFragment.Companion.loadFragment(typeIndex, quesIndex, 0, defaultLoadIndex);
                }
            case "45"://多项对应
                return ParagraphSortingChildLookingFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex, defaultLoadIndex);
            case "VD"://词汇听写
                return ChildWordListenWriteLookReviewFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "78"://复合写作
                switch (childAnswerType) {
                    case 3:
                        return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                    case 4:
                        return CompositionOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "98"://看情景写句子
            case "99"://看图写句子
                return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
        }
        switch (typeNo) {
            case "f"://作文题
                return CompositionOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "W"://短文听写
                if (ConstantBean.Companion.getTaskControlBean().isManu()) {
                    return ManualAnswerLookingFragment.loadQueseFragment(typeIndex, quesIndex, childIndex);
                } else {
                    return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "X"://阅读简答
                if (TextUtils.equals("107", ques.getSpecialFeatureCodes())) {
                    switch (childAnswerType) {
                        case 3:
                            return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                        case 4:
                            return CompositionOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                    }
                }
                if (ConstantBean.Companion.getTaskControlBean().isManu()) {
                    return ManualAnswerLookingFragment.loadQueseFragment(typeIndex, quesIndex, childIndex);
                } else {
                    return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "S"://听力填空
            case "Q":
                String sortIndexType = child.getSortIndexType();
                if (TextUtils.equals(sortIndexType, "0")) {//如果是小题的查看原题
                    return ChildFillOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
                return WebQuesBodyOriginalLookingFragment.Companion.loadFragment(typeIndex, quesIndex, 0, defaultLoadItemIndex);
            case "C"://语法选择，完形填空，对话选择
                return ChildClozeLookReviewFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "D"://阅读理解，阅读判断
                return ChildSelectOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "E": //听力选择
                if (TextUtils.isEmpty(child.getChildAsk())) {
                    return ChildClozeLookReviewFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                } else {
                    return ChildSelectOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "N":
                return ChildFillOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "g": //翻译题
            case "V"://连词成句
                return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case "k"://匹配加简答，匹配加选择， 阅读综合
                switch (childAnswerType) {
                    case 0:
                        return ChildSelectOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                    case 1:
                        return  MultiChildFragment.Companion.loadFragment(typeIndex, quesIndex, defaultLoadIndex);
                    case 2:
                    case 3:
                        return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            case "L"://听力综合
                return ListenMatchAnswerFragment.Companion.loadFragment(typeIndex, quesIndex, childIndex, defaultLoadIndex);
            case "x"://听力匹配
                return ListenParagraphAnalysisFragment.Companion.loadFragment(typeIndex, quesIndex, defaultLoadItemIndex);

        }

        switch (childAnswerType) {
            case 1:
                return ChildSelectOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
            case 2:
            case 4:
                if (ConstantBean.Companion.getTaskControlBean().isManu()) {
                    return ManualAnswerLookingFragment.loadQueseFragment(typeIndex, quesIndex, childIndex);
                } else {
                    return PassageDictationOriginalFragment.loadChildFragment(typeIndex, quesIndex, childIndex);
                }
            default:
                return new WaitToDockFragment();
        }
    }
}
